package com.merlin.security.core.validate.code;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

/**
 * 
 * @author merlin
 *
 */
public class ImageCode {
	
	/**
	 * 图片
	 */
	private BufferedImage image;
	
	/**
	 * 随机数，需要存入session
	 */
	private String code;
	
	/**
	 * 失效时间，单位秒
	 */
	private LocalDateTime expireTime;

	public BufferedImage getImage() {
		return image;
	}

	public void setImage(BufferedImage image) {
		this.image = image;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public LocalDateTime getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(LocalDateTime expireTime) {
		this.expireTime = expireTime;
	}

	public ImageCode(BufferedImage image, String code, LocalDateTime expireTime) {
		super();
		this.image = image;
		this.code = code;
		this.expireTime = expireTime;
	}
	
	/**
	 * 传入过期时间，单位秒
	 * @param image
	 * @param code
	 * @param expireIn 单位秒
	 */
	public ImageCode(BufferedImage image, String code, int expireIn) {
		super();
		this.image = image;
		this.code = code;
		this.expireTime = LocalDateTime.now().plusSeconds(expireIn);//当前时间加上过期时间，失效时间点
	}
	
	/**
	 * 判断验证码是否过期
	 * @return
	 */
	public boolean isExpried() {
		//判断当前时间是不是在过期时间之后
		return LocalDateTime.now().isAfter(expireTime);
	}


	public ImageCode() {
		super();
	}
}
